package com.avic.rong.course.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.activity.login.LoginPhoneActivity;
import com.avic.rong.course.bean.CompanysBean;
import com.avic.rong.course.bean.DealBean;
import com.avic.rong.questionOrAnswer.activity.PersonalHomeActivity;
import com.avic.rong.utils.DensityUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.StringUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.coorchice.library.SuperTextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Chenjiaxin on 2019/8/11 18:19
 * E-Mail Address：16601203965@163.com
 */
public class DealRvAdapter extends RecyclerView.Adapter<DealRvAdapter.DealViewHolder> {

    private Context context;
    private LayoutInflater inflater;

    private List<DealBean> dataList = new ArrayList<>();

    public List<DealBean> getDataList() {
        return dataList;
    }

    public void setDataList(List<DealBean> dataList) {
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }


    public DealRvAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public DealViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.deal_rv_item, viewGroup, false);
        return new DealViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DealViewHolder holder, int position) {
        DealBean dealBean = dataList.get(position);
        holder.orderSn.setText(dealBean.getOrderSn());
        holder.goodsNumber.setText(dealBean.getGoodsNumber() + "");
        holder.goodsPrice.setText(dealBean.getGoodsPrice() + "");
        String replace = dealBean.getPayTime().replace("T", " ");
        holder.payTime.setText(replace.substring(0, replace.indexOf(".")));
        holder.orderAmount.setText(dealBean.getOrderAmount() + "");
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    public class DealViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.orderSn)
        TextView orderSn;
        @BindView(R.id.payTime)
        TextView payTime;
        @BindView(R.id.goodsPrice)
        TextView goodsPrice;
        @BindView(R.id.goodsNumber)
        TextView goodsNumber;
        @BindView(R.id.orderAmount)
        TextView orderAmount;

        public DealViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
